package controller;

import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Handset;
import service.HandsetService;

import java.util.List;

@Controller
public class HandsetController {

    @Autowired
    private HandsetService handsetService;

    @GetMapping("/List")
    public String List(Model model){
        List<Handset> list = handsetService.list();
        model.addAttribute("list",list);

        return "List";
    }
    @GetMapping("/select/{hsId}")
    public String select(@PathVariable("hsId")Integer hsId,Model model){
        Handset select = handsetService.select(hsId);
        model.addAttribute("list1",select);
        return "Select";
    }

    @GetMapping("/delete/{hsId}")
    @ResponseBody
    public String delete(@PathVariable("hsId")Integer hsId){
        int delete = handsetService.delete(hsId);
        return delete>0?"1":"2";
    }
}
